package org.calconnect.icalproofing;

/**
 *	<p>ValidationResults.</p>
 *
 *	<p>Class for packaging the results from an iCalendar validation attempt.
 *	An object of this class is returned from any validator's validate() method.</p>
 *
 *	<p><em>Last checked in by: $Author: aron $ at $Date: 2008-10-23 15:23:16 -0700 (Thu, 23 Oct 2008) $ (UTC)</em></p>
 *
 *	@author Aron Roberts
 *	@version $Revision: 504 $
 *
 */

/*
 * Copyright 2005-2007 Noelios Consulting.
 * 
 * The contents of this file are subject to the terms of the Common Development
 * and Distribution License (the "License"). You may not use this file except in
 * compliance with the License.
 * 
 * You can obtain a copy of the license at
 * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
 * language governing permissions and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL HEADER in each file and
 * include the License file at http://www.opensource.org/licenses/cddl1.txt If
 * applicable, add the following below this CDDL HEADER, with the fields
 * enclosed by brackets "[]" replaced with your own identifying information:
 * Portions Copyright [yyyy] [name of copyright owner]
 */
 
import org.apache.log4j.Logger;

public class ValidationResults {

	// Class variables
	
	// The name of this class
	final static String CLASSNAME = ValidationResults.class.getName();

	// Create a log4j 'logger' for this class, based on the class name
	// This allows us to identify which log events are coming from the
	// methods of this class	
	private static Logger logger = Logger.getLogger( CLASSNAME );
	
	// Message indicating that iCalendar data is valid.
	final static String IS_VALID_MESSAGE = "iCalendar is VALID";
	
	// Instance variables
	boolean valid = false;
	private String msg = "";
	private Exception e = null;
	
	// @todo Expand this set of variables when we may need to capture and
	// transmit additional details of the validation error (e.g. line number,
	// iCalendar excerpts, any data specific to XML representations ...)

	/////////////////////////////////////////////////////////////////
	/**
	 *	Class constructor (no argument).
	 */
	public ValidationResults() {
	
		logger.debug( "In no-argument constructor for " + CLASSNAME + "...");
		
	}

	/////////////////////////////////////////////////////////////////
	/**
	 *	Class constructor.
	 *
	 *	@param		valid		True if the iCalendar data is valid, according to the validator
	 *										routine used; false if it is not.
	 *
	 *	@param		msg	A validation results message.
	 */
	public ValidationResults( boolean valid, String msg ) {
	
	  logger.debug( "In constructor( boolean, String ) for class " + CLASSNAME );
	  
	  this.valid = valid;
	 	
	 	if ( StringUtils.isNotEmpty( msg ) ) {
	 		this.msg = msg;
	 	}
	  
	}

	/////////////////////////////////////////////////////////////////
	/**
	 *	Class constructor.
	 *
	 *	@param		valid		True if the iCalendar data is valid, according to the validator
	 *										routine used; false if it is not.
	 *
	 *	@param		e		An exception.
	 */
	public ValidationResults( boolean valid, Exception e ) {
	
	  logger.debug( "In constructor( boolean, Exception ) for class " + CLASSNAME );
	 	
	  this.valid = valid;

	 	if ( e != null ) {
			this.e = e;
			this.msg = e.getMessage();
		}
	  
	}
	
	/////////////////////////////////////////////////////////////////
	/**
	 *	Returns the validation status.
	 *
	 *  @return		The validation status.
	 */
	public boolean isValid() {
	
		logger.debug( "In isValid() ... in class " + CLASSNAME );
		
		return this.valid;
		
	}

	/////////////////////////////////////////////////////////////////
	/**
	 *	Return the validation results message.
	 *
	 *  @return		The validation results message.
	 */
	public String getMessage() {
	
		logger.debug( "In getMessage() ... in class " + CLASSNAME );
		
		return this.msg;
		
	}

	/////////////////////////////////////////////////////////////////
	/**
	 *	Returns a string representation of this object.
	 *
	 *	@return		A string representation of this object.
	 */
	public String toString() {

		logger.debug( "In toString() for " + CLASSNAME + "...");
		
		return getMessage();
		
	}

	/////////////////////////////////////////////////////////////////

  public static void main( String[] args ) {

		// Display descriptive information about this class

  	System.out.println( CLASSNAME );
  	System.out.println( "$Revision: 504 $" );
  	System.out.println( "$Date: 2008-10-23 15:23:16 -0700 (Thu, 23 Oct 2008) $" );

	} // end of main() method


} // end of class


